package com.pp.controller;


import com.pp.bean.GovIndex;
import com.pp.bean.GovIndexImage;
import com.pp.service.GovIndexService;
import com.pp.util.Respons.ResponseUtil;
import com.pp.util.upload.UploadFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 首页 前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2019-04-03
 */
@Controller
@RequestMapping("/govIndex")
@Api(value = "首页Controller", tags = {"首页类型类"})
public class GovIndexController {

    @Autowired
    GovIndexService govIndexService;



    @RequestMapping(value = "uploadFile",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "上传首页图片")
    public Map uploadFile(@RequestParam("lang") Integer lang,
                          @RequestParam("location")Integer location,
                          MultipartFile file){
        GovIndex govIndex = new GovIndex();
        govIndex.setLang(lang);
        try {
            String url = UploadFile.fileUpload(file);
            govIndex.setUrl(url);
            System.out.println("url:"+url);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        if(govIndexService.save(govIndex)){
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }


    @RequestMapping(value = "select",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询首页")
    public List<GovIndex> select(){
        return govIndexService.list();
    }



}
